<template>
  <van-panel
    :title="item.order_time"
    :desc="item.order_time"
    :status="item.status_text"
    :name="item.id"
    class="order-panel van-hairline--surround"
    @click.native="pushWeblink(item.link)"
  >
    <van-card
      :title="goods.name"
      :desc="goods.sku"
      :num="goods.num"
      :price="goods.price"
      :thumb="goods.thumb"
      v-for="goods in item.goods"
      :key="goods.id"
      class="van-hairline-bottom"
    />
    <template #footer>
      <div class="order_amount">
        <div class="arrow arrow-top"></div>
        共{{item.goods.length}}件商品 实付金额
        <span class="price-cny">{{item.pay}}</span>
      </div>
      <van-button
        size="small"
        v-for="(btn,label) in item.handle"
        :key="btn.id"
        :type="btn.type"
        @click.stop="onClickHandle(label,item.id,key)"
      >
        {{btn.text}}
      </van-button>
    </template>
  </van-panel>
</template>
<script>
import { Icon, Cell, Button, Card, Panel } from 'vant'
export default {
  components: {
    [Icon.name]: Icon,
    [Cell.name]: Cell,
    [Button.name]: Button,
    [Card.name]: Card,
    [Panel.name]: Panel
  },
  name: 'OrderCard',
  props: {
    item: Object,
    tpl: String
  },
  data () {
    return {
      active: false
    }
  },
  computed: {
    format () {
      if (this.tpl) {
        return this.tpl
      }
      return this.data.format
    },
    className () {
      return 'activity-cell__' + this.format
    },
    stats () {
      let stats = []
      stats.push(this.data.category.name)
      stats.push(this.data.publishTime)
      return stats.join(' | ')
    },
    label () {
      if (this.format === 'default') {
        return this.stats
      }
      return ''
    },
    babelTips () {
      if (this.data.format === 'gallery' && this.data.picture_nums > 0) {
        return this.data.picture_nums + '图'
      } else if (this.data.format === 'video' && this.data.duration) {
        return this.data.duration
      }
      return false
    },
    thumb () {
      let albums = this.data.pictures
      if (albums.length > 0 && albums.length < 3) {
        return albums.shift()
      }
      return false
    },
    link () {
      return this.data.link
    }
  },
  methods: {
    onView () {
      console.log(this.link)
      this.pushNativelink(this.link)
    }
  }
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style lang="less" scoped>
.order-panel {
  margin-top: 10px;
  /deep/ .van-cell {
    &:not(:last-child)::after {
      margin-left: 0;
    }
    &__title {
      span {
        font-size: 80%;
        color: #aaa;
        font-weight: 300;
      }
    }
  }

  /deep/ .van-panel__footer {
    text-align: right;
    padding-top: 44px;
    .van-button {
      margin-left: 5px;
    }
    .order_amount {
      position: absolute;
      right: 15px;
      top: 0;
      padding: 10px 0;
      .arrow {
        left: auto;
        right: 10px;
        top: -10px;
      }
    }
  }

  /deep/ .van-card {
    &__title {
      font-size: 14px;
      line-height: 20px;
      max-height: 40px;
    }
    &__desc {
      padding: 5px 0;
      color: #999;
      max-height: 40px;
      line-height: 15px;
    }
    &__bottom {
      display: flex;
      align-items: flex-end;
      justify-content: space-between;
      .van-card__price {
        color: #ff6600;
        &-currency {
          margin-right: 2px;
        }
      }
    }

    &__footer {
      padding-right: 15px;
      padding-left: 100px;
      right: 0;
      bottom: 10px;
      width: 100%;
      .flexbox {
        > * {
          -webkit-box-flex: 1;
          -webkit-flex: 1;
          flex: 1;
        }
        .price-cny {
          font-size: 16px;
        }
        .price-cny:before {
          vertical-align: top;
        }
      }
      .van-button {
        margin: 0;
        width: 30px;
        height: 30px;
        border-radius: 0;
      }
    }
    .van-cell {
      margin: 5px 0;
      padding: 2px 10px;
      background: #f5f5f5;
      &__right-icon {
        transform: rotate(90deg);
        -ms-transform: rotate(90deg);
        -moz-transform: rotate(90deg);
        -webkit-transform: rotate(90deg);
        -o-transform: rotate(90deg);
      }
    }
  }
}
</style>

<style lang="less" scoped>
@import "../../assets/less/functions.less";

.activity-panel {
  position: relative;
  padding: 100px 10px 10px;
  &::after {
    border-radius: 10px;
  }
  &__cover {
    position: absolute;
    left: 0;
    top: 0;
    height: 100px;
    overflow: hidden;
    &::before {
      position: absolute;
      left: 0;
      bottom: 0;
      content: "";
      width: 100%;
      height: 100%;
      .gradient3(transparent, transparent, white);
    }
    img {
      border-radius: 5px 5px 0 0;
      width: 100%;
    }
  }
  &__avatars {
    padding-right: 15px;
    display: -webkit-box;
    display: -webkit-flex;
    display: flex;
    flex-direction: row-reverse;
    span {
      display: inline-block;
      width: 15px;
      img {
        width: 20px;
        height: 20px;
        border-radius: 50%;
        border: 1px solid #ccc;
      }
    }
    &:empty {
      padding-right: 0;
    }
  }
  &__tips {
    flex: 1;
  }

  &__header,
  &__footer {
    -moz-box-align: center;
    -moz-box-pack: justify;
    align-items: center;
    align-content: space-around;
    box-sizing: border-box;
    display: -webkit-box;
    display: -webkit-flex;
    display: flex;
    justify-content: center;
    overflow: hidden;
    flex-wrap: nowrap;
    width: 100%;
    position: relative;
  }
  &__header {
    padding: 10px 0 5px;
    &-date {
      flex: 0 1 auto;
      width: 44px;
      padding-right: 10px;
      text-align: center;
      > * {
        margin: 0;
      }
      h2 {
        font-size: 20px;
        font-weight: bold;
      }
      p {
        font-size: 10px;
        margin-top: 10px;
      }
    }
    &-title {
      flex: 1;
      > * {
        margin: 0;
      }
      h2 {
        font-size: 16px;
        line-height: 24px;
      }
      p {
        font-size: 10px;
        margin-top: 3px;
        color: #aaa;
        font-weight: 300;
        line-height: 18px;
      }
    }
    &-status {
    }
  }
  &__footer {
    padding-top: 10px;
  }
}
</style>
